package com.app.manage.moudles.system.contoller;

import com.app.manage.moudles.system.dao.TConfDao;
import com.app.manage.moudles.system.entity.TConf;
import com.app.manage.utils.Rsp;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("conf")
public class TConfController {


    @Resource
    private TConfDao confDao;

    @GetMapping("addServerCheckConf")
    public Rsp addServerCheckConf(String times){
        TConf tConf = confDao.selectOne(
                new LambdaQueryWrapper<TConf>().eq(TConf::getConfType,"server_check").eq(TConf::getConfName,"time_split").last("limit 1")
        );

        if(tConf == null){
            TConf c = new TConf();
            c.setConfType("server_check");
            c.setConfTypeName("服务器状态检测时间间隔(s)");
            c.setConfName("time_split");
            c.setConfValue(times);
            confDao.insert(c);
        }else {
            tConf.setConfValue(times);
            confDao.updateById(tConf);
        }
        return Rsp.success();
    }

    @GetMapping("getServerCheckTime")
    public Rsp getServerCheckTime(){
        TConf tConf = confDao.selectOne(
                new LambdaQueryWrapper<TConf>().eq(TConf::getConfType,"server_check").eq(TConf::getConfName,"time_split").last("limit 1")
        );
        return Rsp.success(tConf == null ?"-1":tConf.getConfValue());
    }

}
